
#不带参数的函数装饰器
def decorator_func(func):
    def do_somethings():
        print('this is wrap function!')
        func()
    return do_somethings

@decorator_func
def be_decorator():
    print('be decorators!')
    pass

# 函数带参数的装饰器
def decorator_func1(func):
    def decorator(*args, **kwargs):
        print(func.__name__ +' func be decorated!')
        return func(*args,**kwargs)
    return decorator
@decorator_func1
def be_decorator1(x):
    print('参数是：{}'.format(x))

@decorator_func1
def be_decorator2(y):
    print('参数是：{}'.format(y))

#高级一点装饰器，装饰器可以带参数装饰器
def log(level):
    def wrapper(func):
        def decorator(*args,**kwargs):
            print('[{}]:开始装饰!'.format(level))
            func(*args,**kwargs)
            print('[{}]:装饰结束！'.format(level))
        return decorator
    return wrapper

@log(level='ERROR')  
def log_decorator(z):
    print('参数是：{}'.format(z))

if __name__ == '__main__':
    be_decorator()
    # print(__name__)
    be_decorator1(x=10)
    be_decorator2(12)
    # log 测试
    # 相当于 log('ERROR')log_decorator(13)
    log_decorator(13) #=log('ERROR')(log_decorator(13))